					
package com.module.device.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Session;

import base.util.Page;

import com.module.device.manager.DeviceLoginRecordManager;
import com.module.device.vo.DeviceLoginRecord;
import com.module.prms.manager.UserManager;
import com.module.prms.vo.PrmsUser;

public class DeviceLoginRecordService {

	UserManager um = UserManager.getInstance();
	
	public Page list(DeviceLoginRecord bean, Integer start, Integer limit)
			throws Exception {
		Page page = new Page();
		page.setStart(start);
		page.setLimit(limit);
		//bean.setUserId(LoginSession.getUserid());
		DeviceLoginRecordManager manager = DeviceLoginRecordManager.getInstance();
		page = manager.list(page, bean);
		return page;
	}

	public Map<String,Object> remove(Long id)throws Exception{       
		Map<String,Object> map = new HashMap<String,Object>();
		DeviceLoginRecordManager manager = DeviceLoginRecordManager.getInstance();
		map = manager.delete(id);
		return map;
		
	}	


	public Map<String,Object> save(DeviceLoginRecord bean)throws Exception{
		//bean.setOrgId(LoginSession.getOrgid());
		Map<String,Object> map = new HashMap<String,Object>();
		DeviceLoginRecordManager manager = DeviceLoginRecordManager.getInstance();
		map = manager.add(bean);
		return map;

	} 
	

	public DeviceLoginRecord findById(Long id)throws Exception{
		DeviceLoginRecord bean = new DeviceLoginRecord();
		DeviceLoginRecordManager manager = DeviceLoginRecordManager.getInstance();
		bean = manager.findById(id);
		return bean;
	}
	
	  /**
	   * 根据软件编码查找
	   * @param softwarecode
	   * @return
	   * @throws Exception
	   */
	   public DeviceLoginRecord findeBySoftwareCode(String softwarecode) throws Exception{
		   DeviceLoginRecord bean = new DeviceLoginRecord();
			DeviceLoginRecordManager manager = DeviceLoginRecordManager.getInstance();
			bean = manager.findeBySoftwareCode(softwarecode);
			PrmsUser pu = new PrmsUser();
			pu.setCuserId(bean.getUserId());
			try{
				pu=um.findebyid(pu);
			}catch(Exception e)
			{
				e.printStackTrace();
			}
			if(pu!=null)
			{
			bean.setTrueName(pu.getCuserTruename()==null?"":pu.getCuserTruename());
			}
			return bean;
	   }
	
public static void main(String args[]) throws Exception
{
	DeviceLoginRecordService drs = new DeviceLoginRecordService();
	drs.findeBySoftwareCode("00851");
}
}
